home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mcomm / txzm.c < prev    next >
C/C++ Source or Header  |  1994-10-02  |  58KB  |  1,666 lines

  1.  
  2. /*/////////////////////////////////////////////////////////////////////
  3. //                                                                   //
  4. //  TXZM.C -- zmodem protocol driver (formerly ZMP)                  //
  5. //                                                                   //
  6. //    (c) 1991-94, Mike Dumdei, 6 Holly Lane, Texarkana TX, 75503    //
  7. //                                                                   //
  8. //////////////////////////////////////////////////////////////////// */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stdarg.h>
  12. #include <string.h>
  13. #include <process.h>
  14. #include <ctype.h>
  15. #include <io.h>
  16. #include <dos.h>
  17. #include <bios.h>
  18. #include "comm.h"
  19. #include "ansidrv.h"
  20. #include "extra.h"
  21. #include "colors.h"
  22. #include "zmdos.h"
  23.  
  24. #if defined (__TURBOC__)
  25.   #include <dir.h>
  26.   #define ChDrive(d) setdisk((d)-1)
  27.   #pragma warn -par
  28.   #ifdef _RTLENTRY              // BC4 or greater
  29.       #pragma option -x- -RT-
  30.       void _ExceptInit(void) {} // disable exception handling
  31.   #endif
  32. #elif defined (__ZTC__)
  33.   #include <direct.h>
  34.   #define ChDrive(d) _chdrive(d)
  35. #elif defined (__MSC__)
  36.   int ndrives;
  37.   #define ChDrive(d) _dos_setdrive((d), &ndrives)
  38. #endif
  39.  
  40. #define ALT_C       0x2e00
  41. #define ALT_D       0x2000
  42. #define ALT_E       0x1200
  43. #define ALT_H       0x2300
  44. #define ALT_L       0x2600
  45. #define ALT_P       0x1900
  46. #define ALT_R       0x1300
  47. #define ALT_S       0x1f00
  48. #define ALT_X       0x2d00
  49. #define FK1         0x3b00
  50. #define PGUP        0x4900
  51. #define PGDN        0x5100
  52. #define ALT_EQU     0x8300
  53. #define X_ESC       0x011b
  54.  
  55. void AddToList(char *subdir);
  56. char *CaptureBaudRate(void);
  57. char *ConvertSecs(long secs);
  58. int Dial(void);
  59. void DrawBox(int row, int col, int nrows, int ncols, int color, int style);
  60. void DspZmodemScrn(void);
  61. char *ExpandSubDirs(char *fnames);
  62. int FileTransfer(void);
  63. int GetNumber(void);
  64. long getHunds(void);
  65. long getSeconds(void);
  66. void HelpFunc(void);
  67. void InitDefaults(void);
  68. void MiniTermMode(void);
  69. void ProcCmdLine(int argc, char * *argv);
  70. int prompt(char *buf, int maxlen);
  71. void ReadDialDir(void);
  72. int RecurseSubDirs(char *sd);
  73. int RepeatDial(void);
  74. void SetFIFOLevels(int rxFIFOlevel, int txFIFOlevel);
  75. int SetParams(char *newparams);
  76. void usage(void);
  77. void vDisplay(int row, int col, char *format, ...);
  78. int waitfor(int ticks, ...);
  79. void ZMsg(int type, ...);
  80.  
  81. extern int  _C_ TestDesqView(void);
  82. extern int  _C_ DV_VideoSeg(int);
  83. extern void _C_ DV_TimeSlice(void);
  84.  
  85. /*/////////////////////////////////////////////////////////
  86. //  Configuration structure.  Structure is used to allow //
  87. //  the defaults to be changed modifying the EXE.        //
  88. //  "TXZMCFG:" is the tag to search for to find the start//
  89. //  of the structure in the EXE.                         //
  90. //////////////////////////////////////////////////////// */
  91. struct PROTCONFIG
  92. {
  93.     char    tag[8], DLPath[80], ULPath[80];
  94.     long    LocBaud, MinFifoBaud;
  95.     int     ComBase, IRQ, Vctr;
  96.     int     h_VBufSize, h_BufSize, b_VBufSize, b_BufSize;
  97.     int     TxWindow, ZExistOpts, XYExistOpts;
  98.     int     FifoTxLvl, FifoRxLvl;
  99.     char    IgnCarrier, MsrFlow, KeepTime, EscCtl, OvlyIO;
  100.     char    Color[10], Mono[10];
  101. } cfg =
  102. {
  103.     "TXZMCFG:", "", "",
  104.     0L, 1L,
  105.     0x3f8, IRQ4, VCTR4,
  106.     2048, 0, 20508, 20480,
  107.     0, 1, 2,
  108.     8, 8,
  109.     0, 0, 1, 0, 1,
  110.     {  WHT|BLU_B,  H_GRN|BLU_B,  H_RED|BLU_B,    YLW|BLU_B,
  111.        GRY|BLU_B,    YLW|BLU_B,  H_RED|BLU_B,  H_MAG|BLU_B,
  112.        CYN,              CYN_B  },
  113.     { WHT, WHT, RVRS, H_WHT, WHT, H_WHT, H_WHT, H_WHT, WHT, WHT_B }
  114. };
  115.  
  116. /*/////////////////////////////////////////////////////////
  117. //  Screen data structure                                //
  118. //////////////////////////////////////////////////////// */
  119. typedef struct
  120. {
  121.     int row, col, color, count;
  122.     char *text;
  123. } SCREENDATA;
  124.  
  125. /*/////////////////////////////////////////////////////////
  126. //  Dial directory structure                             //
  127. //////////////////////////////////////////////////////// */
  128. static struct DIAL_DIRECTORY
  129. {
  130.     char *num;
  131.     char *name;
  132. } DialDir[10];
  133.  
  134. /*/////////////////////////////////////////////////////////
  135. //  Global variables                                     //
  136. //////////////////////////////////////////////////////// */
  137. ASYNC port;                 /* ASYNC port structure */
  138. int combase, irq, vctr;     /* port address, IRQ number, & vector */
  139. int openmask = 0;           /* mask for forcing no FIFOs, no MSR intrpts */
  140. long LocBaud = 0L;          /* CPU to modem/device baud rate */
  141. char params[12] = "";       /* port parameters */
  142. char lockedbaud[12] = "";   /* locked baud parameter */
  143. char fnames[256] = "";      /* list of files to send if sending */
  144. char minsecs[10];           /* seconds to min:secs buffer */
  145. char *color;                /* pointer to list of colors */
  146. int txtcolor;               /* color of most screen message output */
  147. char buf[256];              /* general purpose buffer */
  148. int goodargs = 0;           /* got an 'r' or an 's' on command line */
  149. char *node = NULL;          /* for bbs use: LASTUSER.BBS format file name */
  150. int miniterm = 0;           /* mini-terminal mode selected */
  151. char OvlyIO;                /* overlay disk and serial I/O flag */
  152. char *flist;                /* used when expanding subdirectories */
  153. char mask[14];              /* used when expanding subdirectories */
  154. int plen;                   /* used when expanding subdirectories */
  155. int tryDV = 0;              /* cmdline switch to test for DesqView */
  156. int checkcarrier = 0;       /* check for carrier during 'waitfor' flag */
  157. int stripmask = 0xff;       /* strip high bit mask for miniterm mode */
  158. char phone[40] = "";        /* phone number to dial */
  159. char DialPrefix[16] = "ATDT"; /* default dial prefix */
  160. char *OverrideName = NULL;  /* cmdline rx filename used if not NULL */
  161. char OverrideFlag = '\0';   /* if '/', above specifies complete pathname */
  162.  
  163. long PrevSecs = -1L;        /* used by getSeconds to handle midnight */
  164. long PrevHunds = -1L;       /* used by getHunds to handle midnight */
  165. long tfBytes, tCPS;         /* total bytes transferred, average CPS */
  166. int tFiles;                 /* number of files transferred */
  167.  
  168. /* variables & dummy function to disable display of file transfer screen */
  169. int qf = 0;
  170. void DoNothing(int r, int c, int a, char *s) {}
  171. void (*DspMsgAt[2])(int, int, int, char *) = { d_msgat, DoNothing };
  172.  
  173.  
  174. /*/////////////////////////////////////////////////////////
  175. //                                                       //
  176. //      Main                                             //
  177. //                                                       //
  178. //:mai////////////////////////////////////////////////// */
  179. void cdecl main(int argc, char *argv[])
  180. {
  181.     int i, FIFOretry = 0;
  182.  
  183.     color = ((initvid() & 0xff) == CO80) ? cfg.Color : cfg.Mono;
  184.     txtcolor = (int)color[1] & 0xff;
  185.     InitDefaults();
  186.     ProcCmdLine(argc, argv);
  187.     if (!goodargs)
  188.         usage();
  189.  
  190.     if (tryDV && TestDesqView() != 0)
  191.     {
  192.         i = DV_VideoSeg(v_seg);
  193.         if (v_seg != i)
  194.             v_seg = i, v_snow = 0;
  195.     }
  196.     if (*params)
  197.         ConnectBaud = atol(params);
  198.     if (*lockedbaud)
  199.         LocBaud = atol(lockedbaud);
  200.     if (LocBaud == 0L)
  201.         LocBaud = ConnectBaud;
  202.     if (LocBaud != 0L)
  203.     {
  204.         sprintf(params, "%ldN81", LocBaud);
  205.         if (LocBaud < cfg.MinFifoBaud)
  206.             openmask |= 0x4000;
  207.     }
  208.  
  209.     if (OvlyIO)
  210.         VBufSize = cfg.h_VBufSize, BufSize = cfg.h_BufSize;
  211.     else
  212.         VBufSize = cfg.b_VBufSize, BufSize = cfg.b_BufSize;
  213.     if (BufSize)
  214.         ZFR0 &= ~CANOVIO;
  215.  
  216.     AllocRingBuffer(&port, 2048, 4096, 0);
  217.     tickhookset(1);
  218.     while (1)
  219.     {
  220.         i = async_open(&port, combase, irq, vctr|openmask, params);
  221.         if (i != 0)
  222.         {
  223.             if (i == 512 && (port.Stat3 & B_FIFO) && FIFOretry == 0
  224.              && !(openmask & 0x4000))
  225.             {
  226.                 openmask |= 0x4000;
  227.                 FIFOretry = 1;      /* FIFO retry code fixes s